package yxy.game.pm2.command.union;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.UnionMessage;
import yxy.game.pm2.module.union.UnionHandle;
import yxy.game.pm2.module.union.UnionHandle.UnionPlayerEntry;

/** 联盟 联盟快速加入 */
@MessageType(proto = Command.UnionQuick, classtype = UnionMessage.UnionQuickRequest.class)
public class CMD_UnionQuick extends Command<UnionMessage.UnionQuickRequest> {

	@Override
	public void execute(MessageSource messageSource, UnionMessage.UnionQuickRequest request) {
		String playerCode = messageSource.getTag();
		{
			UnionMessage.UnionQuickResponse.Builder response = UnionMessage.UnionQuickResponse.newBuilder();

			UnionPlayerEntry entry = new UnionPlayerEntry(playerCode);
			Result result = new UnionHandle().checkPlayerUnion(entry);
			if (!result.equals(Result.UnionOut)) {
				send(messageSource, response, result);
				return;
			}

			// TODO 处理快速进入

			send(messageSource, response, Result.Success);
		}

//		UnionMessage.UnionMainResponse.Builder unionMessage = new UnionHandle().unionMain(playerCode);
//		MessageEmitterHandler.getInstance().send(messageSource, unionMessage.build());
	}

	private void send(MessageSource messageSource, UnionMessage.UnionQuickResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}